package com.xuecheng.content.api;

import com.xuecheng.base.exception.ValidationGroups;
import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.content.model.dto.AddCourseDto;
import com.xuecheng.content.model.dto.CourseBaseInfoDto;
import com.xuecheng.content.model.dto.EditCourseDto;
import com.xuecheng.content.model.dto.QueryCourseParamsDto;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.service.CourseBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Mr.M
 * @version 1.0
 * @description 课程信息管理
 * @date 2023/2/11 15:44
 */
@Api(value = "课程信息管理接口",tags = "课程信息管理接口")
@RestController
public class CourseBaseInfoController {
    @Autowired
    private CourseBaseService courseBaseService;
    @ApiOperation("课程查询接口")
    @PostMapping("/course/list")
    public PageResult<CourseBase> list(PageParams pageParams, @RequestBody(required=false) QueryCourseParamsDto queryCourseParamsDto) {

        PageResult pageResult = courseBaseService.queryCourseBaseList(pageParams,queryCourseParamsDto);
        return pageResult;

    }
    @ApiOperation("课程添加接口")
    @PostMapping("/course")
    public CourseBaseInfoDto createCourseBase(@RequestBody @Validated(ValidationGroups.Insert.class) AddCourseDto addCourseDto){
        Long companyId = 1232141425L;
        CourseBaseInfoDto courseBaseInfoDto = courseBaseService.createCourseBase(companyId,addCourseDto);
        return courseBaseInfoDto;
    }
    @ApiOperation("根据课程Id查询课程")
    @GetMapping ("/course/{CourseId}")
    public CourseBaseInfoDto getCourseById(@PathVariable("CourseId") Long CourseId){
        CourseBaseInfoDto courseBaseInfoDto = courseBaseService.getCourseBaseInfo(CourseId);
        return courseBaseInfoDto;
    }
    @ApiOperation("根据课程Id修改课程")
    @PutMapping ("/course")
    public CourseBaseInfoDto Update(@RequestBody @Validated(ValidationGroups.Update.class) EditCourseDto editCourseDto){
        Long companyId = 1232141425L;
        CourseBaseInfoDto courseBaseInfoDtoNew = courseBaseService.updateCourseBaseInfoDto(companyId,editCourseDto);
        return courseBaseInfoDtoNew;
    }
}
